﻿using Sinacor.Infra.Common.Exceptions;
using Sinacor.Infra.Service.ExceptionHandling;
using System;
using System.Collections.Generic;
using System.Text;
using Sinacor.Servico.Bovespa.Ordens;
using Sinacor.Infra.Service.Common;

namespace Sinacor.Servico.Bovespa.Ordens.BusinessLogic
{
	public class Bolsa : BaseBusinessLogic
	{
        #region Constantes de Erro

        private const int ERRO_BOLSA_BOLSAINEXISTENTE = 103072;

        #endregion

		/// <summary>
        /// Validar codigo de bolsa
		/// Autor: Eduardo Sertorio
        /// Data: 07/01/2008
		/// </summary>
		/// <param name="codigoBolsa">string</param>
        /// <returns>bool</returns>
		public bool ValidarPorCodigo(string codigoBolsa)
		{
			BusinessEntity.Bolsa response = (new ResourceAccess.Bolsa()).ConsultarPorCodigo(codigoBolsa);
            return (response != null);
		}

        /// <summary>
        /// Consultar bolsa por codigo
        /// Autor: Eduardo Sertorio
        /// Data: 07/01/2008
        /// </summary>
        /// <param name="request">BusinessEntity.Bolsa</param>
        /// <returns>BusinessEntity.Bolsa</returns>
		public BusinessEntity.Bolsa ConsultarBolsaCodigo(BusinessEntity.Bolsa request)
		{
            return (new ResourceAccess.Bolsa()).ConsultarPorCodigo(request.Codigo);	
		}
        /// Historico: ALT01
        /// Data : 10/01/2007
        /// Autor: Luciano Azevedo
        /// Obs.: Adicionada costante de Erro
        /// </summary>
        /// <returns></returns>        
		public void ValidarCodigo(string codigo)
		{
			ResourceAccess.Bolsa bolsaDataAccess = new ResourceAccess.Bolsa();
			BusinessEntity.Bolsa bolsa = bolsaDataAccess.ConsultarBolsa(codigo);

			if (bolsa.Codigo == null)
                throw new BusinessException(ERRO_BOLSA_BOLSAINEXISTENTE);			
		}

		public List<BusinessEntity.Bolsa> ConsultarBolsas()
		{
            ResourceAccess.Bolsa bolsa = new ResourceAccess.Bolsa();
            return bolsa.ConsultarBolsas();
		}
    }
}
